package com.example.blog.service;

import com.example.blog.mapper.BlogMapper;
import com.example.blog.mapper.UserInfoMapper;
import com.example.blog.model.BlogInfo;
import com.example.blog.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j

@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogMapper blogMapper;

    public UserInfo selectById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    public UserInfo selectByName(String userName) {

        return userInfoMapper.selectByName(userName);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        //1.根据博客ID 获取作者ID
        //2.根据作者ID 获取作者信息
        BlogInfo blogInfo = blogMapper.selectById(blogId);
        if (blogInfo==null &&blogInfo.getUserId()<=0){
            log.error("图书不存在或作者信息不存在,blogId:{}",blogId);
            return null;
        }
       return userInfoMapper.selectById(blogInfo.getUserId());

    }
}
